import {
  searchFamilyName,
  getPersonInfoApi
} from "../../services/filing/filing"
import {
  GETSTORAGE
} from "../../services/storage/storage"
Page({


  data: {
    familyName: ''
  },

  getFamilyName() {
    const familyId = GETSTORAGE('familyId')
    const userId = GETSTORAGE('userId')

    searchFamilyName({
      familyId
    }).then(res => {
      this.setData({
        familyName: res.data.data.familyName
      })
    })
    getPersonInfoApi({
      userId
    }).then(res => {
      const {
        familyIds,
      } = res.data.data
      let list = []
      familyIds.forEach(item => {
        searchFamilyName({
          familyId: item
        }).then(res => {
          console.log(res);
          if (item != familyId) {
            list.push({
              label: res.data.data.familyName,
              value: item
            })
          } else {
            list.unshift({
              label: this.data.familyName,
              value: familyId
            })
          }
          this.setData({
            familys: list,
            // familyName: list[0].label
          })
          console.log(list, '所有家庭');
        })
      })
    })
  },
  onPickerChange(e) {
    const {
      key
    } = e.currentTarget.dataset;
    const {
      value,
      label
    } = e.detail;
    console.log('picker change:', e.detail);
    this.setData({
      familyName: label[0],
      personageName: label[1],
    });
  },
  // picke取消
  onPickerCancel(e) {
    const {
      key
    } = e.currentTarget.dataset;
    console.log(e, '取消');
    console.log('picker1 cancel:');
    this.setData({
      [`${key}Visible`]: false,
    });
  },
  onColumnChange(e) {
    console.log(e);
    const {
      column,
      value
    } = e.detail
    console.log(e.detail);
    if (column == 1) return
  },
  onSeasonPicker() {
    this.setData({
      dateVisible: true
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getFamilyName()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})